<?php

namespace app\index\controller;

use think\exception\ValidateException;
use app\model\RegisterField;
use app\model\CollectForms;

class CollectformsController extends Base
{

    public function update()
    {
        $id = input('post.id', '', 'intval');
        if (empty($id)) {
            $id = input('post.orderid', '', 'serach_in');
        }
        $registerfield['fields'] =  json_decode(input('post.registerfield'), true);
        $data = RegisterField::fieldToData($registerfield)['data'];
        $data['uid'] = UID();
        $data['weid'] = weid();
        $data['ptype'] = $registerfield['fields'][0]['ptype'];
        $data['status'] = 0;
        CollectForms::create($data);

        $msg = '提交成功';
        return $this->json(['msg' => $msg, 'data' => $data]);
    }
}
